from rest_framework.viewsets import ModelViewSet

from meiduo_admin.good import spec_options_serializers
from meiduo_admin.my_paginate import MyPageNumberPagination
from goods.models import SpecificationOption,SPUSpecification
from .spec_options_serializers import SpecOptionsSerializers

from rest_framework.generics import ListAPIView
# 1,spec option信息
class SpecOptionsViewset(ModelViewSet):
    pagination_class = MyPageNumberPagination
    serializer_class = SpecOptionsSerializers
    queryset = SpecificationOption.objects.all()

# 2， spec信息

class OptionSpecView(ListAPIView):
    serializer_class = spec_options_serializers.OptionSpecSerializer
    # queryset = SPUSpecification.objects.all()

    # 重写数据源
    def get_queryset(self):
        queryset = SPUSpecification.objects.all()
        for spec in queryset:
            spec.name="{}-{}".format(spec.spu.name,spec.name)
        return queryset